#include "mypushbutton.h"
#include <QDebug>
#include <QPropertyAnimation>
// MyPushButton::MyPushButton(QWidget *parent)
//     : QWidget{parent}
// {}

MyPushButton::MyPushButton(QString normalImage, QString pressImage)
{
    this->normalImage = normalImage;
    this->pressImage = pressImage;

    QPixmap pix;
    if(!pix.load(this->normalImage))
    {
        qDebug() << "path error";
        return ;
    }
    this->setFixedSize(pix.width(), pix.height());//设置大小

    setStyleSheet("QPushButton{border:0px}");//设置不规则

    //设置图标
    setIcon(pix);
    setIconSize(QSize(pix.width(), pix.height()));

}

void MyPushButton::zoom()
{
    QPropertyAnimation* ani = new QPropertyAnimation(this, "geometry");//弹跳动画
    ani->setDuration(500);
    ani->setStartValue(QRect(x(), y(), width(), height()));
    ani->setEndValue(QRect(x(), y() + 7, width(), height()));
    ani->setEasingCurve(QEasingCurve::OutBounce);
    ani->start();

    QPropertyAnimation* ani2 = new QPropertyAnimation(this, "geometry");//弹跳动画
    ani2->setDuration(500);
    ani2->setStartValue(QRect(x(), y() + 7, width(), height()));
    ani2->setEndValue(QRect(x(), y(), width(), height()));
    ani2->setEasingCurve(QEasingCurve::OutBounce);
    ani2->start();
}

void MyPushButton::mousePressEvent(QMouseEvent* e)
{
    if(pressImage != "")
    {
        QPixmap pix;
        if(!pix.load(this->pressImage))
        {
            qDebug() << "path error";
            return ;
        }
        this->setFixedSize(pix.width(), pix.height());//设置大小
        qDebug() << "success press";
    }
    return QPushButton::mousePressEvent(e);
}

void MyPushButton::mouseReleaseEvent(QMouseEvent* e)
{
    QPixmap pix;
    if(!pix.load(this->normalImage))
    {
        qDebug() << "path error";
        return ;
    }
    qDebug() << "Release success";
    this->setFixedSize(pix.width(), pix.height());//设置大小
    return QPushButton::mouseReleaseEvent(e);
}

void MyPushButton::setNum(QString label)
{
    this->label = label;
}

void showMyLabel()
{

}
